package com.sugon.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.consts.ErmsCodePrefix;
import com.sugon.dao.SpecialDevPressureChannelDao;
import com.sugon.entity.SpecialDevPressureChannelEntity;
import com.sugon.service.SpecialDevPressureChannelService;
import com.sugon.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 特种设备-压力管道台账Service实现类
 *
 * @author YuXD
 * @date 2021-09-18
 */
@Service("specialDevPressureChannelService")
public class SpecialDevPressureChannelServiceImpl implements SpecialDevPressureChannelService {

    @Autowired
    private SpecialDevPressureChannelDao specialDevPressureChannelDao;

    @Override
    public SpecialDevPressureChannelEntity queryObject(String id) {
        return specialDevPressureChannelDao.queryObject(id);
    }

    @Override
    public List<SpecialDevPressureChannelEntity> queryList(Map<String, Object> map) {
        return specialDevPressureChannelDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return specialDevPressureChannelDao.queryTotal(map);
    }

    @Override
    public String generateUniqueCode() {
        String lastestEquipmentCode = specialDevPressureChannelDao.getLastestEquipmentCode(ErmsCodePrefix.PRESSURE_CHANNEL_CODE_PREFIX);
        return com.sugon.modules.utils.StrUtil.increase(lastestEquipmentCode, ErmsCodePrefix.PRESSURE_CHANNEL_CODE_PREFIX, 5, 1);
    }

    @Override
    public int save(SpecialDevPressureChannelEntity specialDevPressureChannel) {
        specialDevPressureChannel.setId(RandomUtil.randomString(32));
        specialDevPressureChannel.setGmtCreate(DateUtil.date());
        specialDevPressureChannel.setCreateUser(ShiroUtils.getUserId());
        specialDevPressureChannel.setEquipmentCode(generateUniqueCode());
        return specialDevPressureChannelDao.save(specialDevPressureChannel);
    }

    @Override
    public int update(SpecialDevPressureChannelEntity specialDevPressureChannel) {
        specialDevPressureChannel.setGmtModified(DateUtil.date());
        specialDevPressureChannel.setUpdateUser(ShiroUtils.getUserId());
        return specialDevPressureChannelDao.update(specialDevPressureChannel);
    }

    @Override
    public int delete(String id) {
        return specialDevPressureChannelDao.delete(id);
    }

    @Override
    public int deleteBatch(String[] ids) {
        return specialDevPressureChannelDao.deleteBatch(ids);
    }
}
